<template>
  <div class="app-container" id="follow">
    <el-form ref="form" :model="form" :rules="rules" label-width="179px" class="demo-form-inline">
      <el-card class="box-card a1">
        <p><i class="el-icon-edit" style="width: 20px"></i>老年衰弱（肌少症）干预<span style="margin-left: 20px"></span></p>
        <el-form-item label="姓名">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
          <el-form-item label="年龄">
          <el-input v-model="form.age"></el-input>
        </el-form-item>
        <el-form-item label="现住地址">
          <el-input v-model="form.address"></el-input>
        </el-form-item>
        <el-form-item label="联系电话">
          <el-input v-model="form.tel"></el-input>
        </el-form-item>
        <el-form-item label="">
          <el-radio v-model="form.screeningItem" label="衰弱前期"></el-radio>
          <el-radio v-model="form.screeningItem" label="衰弱"></el-radio>
          <el-radio v-model="form.screeningItem" label="肌少症"></el-radio>
        </el-form-item>
        <el-form-item label="">
          <el-checkbox v-model="form.lnpgIs">老年综合评估</el-checkbox>
          <el-checkbox v-model="form.yyzcIs">营养支持</el-checkbox>
          <el-checkbox v-model="form.yddlIs">运动锻炼</el-checkbox>
          <el-checkbox v-model="form.rzxlIs">认知训练</el-checkbox>
          <el-checkbox v-model="form.xlzxIs">心理咨询</el-checkbox>
          <el-checkbox v-model="form.yfddIs">预防跌倒</el-checkbox>
          <el-checkbox v-model="form.dcyyIs">多重用药管理</el-checkbox>
          <el-checkbox v-model="form.jkjyIs">健康教育</el-checkbox>
        </el-form-item>
        <el-form-item label="就诊医院">
          <el-input v-model="form.hospital"></el-input>
        </el-form-item>
      </el-card>

      <el-form-item style="margin-top: 15px">
        <el-button type="primary" @click="onSubmit">保存</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {getFollow, addFollow, updateFollow } from "@/api/his/follow";
import { tansParams } from '@/utils/ruoyi'
import axios from 'axios'
import { getToken } from '@/utils/auth'
import { getPatient } from '@/api/his/patient'

export default {
  name: 'PatientGy',
  dicts: [],
  data() {
    return {
      btnLoading: false,
      form: {
        id:null,
        followId:null,
        username:null,
        age:null,
        address:null,
        tel:null,
        patientId:null,
        lnpgIs:false,
        yyzcIs:false,
        yddlIs:false,
        rzxlIs:false,
        xlzxIs:false,
        yfddIs:false,
        dcyyIs:false,
        jkjyIs:false,
        screeningItem:'',
        hospital:'',
        status:'' //干预
      },
      follow:{},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.init();
  },
  mounted() {
  },
  methods: {
    init(){
      const id = this.form.patientId = this.$route.params && this.$route.params.id;
          getFollow(id).then(response => {
            //console.log('response=>'+JSON.stringify(response))
            //if(response.total>0) {
              var status = this.form.status = response.data.status == null ? '' : response.data.status
              if (status.indexOf('2') == -1) {
                //没有干预过
                this.form.status = status + '@' + '2' //1：已随访
              }
            //console.log('this.form.status==>',this.form.status)
            if(response.data.id!=null) {
              this.form.followId = this.form.id = response.data.id;
              this.form.lnpgIs = response.data.lnpgIs == 'true' ? true : false
              this.form.yyzcIs = response.data.yyzcIs == 'true' ? true : false
              this.form.yddlIs = response.data.yddlIs == 'true' ? true : false
              this.form.rzxlIs = response.data.rzxlIs == 'true' ? true : false
              this.form.xlzxIs = response.data.xlzxIs == 'true' ? true : false
              this.form.yfddIs = response.data.yfddIs == 'true' ? true : false
              this.form.dcyyIs = response.data.dcyyIs == 'true' ? true : false
              this.form.jkjyIs = response.data.jkjyIs == 'true' ? true : false
              this.form.screeningItem = response.data.screeningItem;
              this.form.username = response.data.username
              this.form.age = response.data.age
              this.form.address= response.data.usual
              this.form.tel= response.data.telephone
              this.form.hospital = response.data.hospital
              this.form.createTime = Date.now();
            }else{
              getPatient(id).then(response => {
                this.form.username = response.data.patientName
                this.form.age = response.data.age
                this.form.address= response.data.address
                this.form.tel= response.data.telephone
                this.form.updateTime = Date.now();
              })
            }
          });

    },
    onSubmit() {
      //提交表单
      this.$refs["form"].validate(valid => {
        this.form.id = this.form.followId;
        this.form.usual = this.form.address;
        this.form.telephone = this.form.tel;
        if (this.form.followId != null) {
          //this.form.username = this.form.patientName;
          //this.form.telephone = this.form.tel;
          //this.form.usual = this.form.address;
          //console.log('updateFollow ',this.form);return
          updateFollow(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
          });
        } else {
          addFollow(this.form).then(response => {
            this.$modal.msgSuccess("新增成功");
          });
        }
        //关闭tab
        this.$store.dispatch("tagsView/delView", this.$route);
        this.$router.go(-1);
      })
    },
    delView({ dispatch, state }, view) {
      return new Promise(resolve => {
        dispatch('delVisitedView', view)
        dispatch('delCachedView', view)
        resolve({
          visitedViews: [...state.visitedViews],
          cachedViews: [...state.cachedViews]
        })
      })
    },    // 表单重置
    reset() {
      this.form = {
      };
      this.resetForm("form");
    },

    onCancel(){
      //关闭tab
      this.$store.dispatch("tagsView/delView", this.$route);
      this.$router.go(-1);
    },

  }
}
</script>


<style lang="scss" scoped>
#follow .el-form-item {
  margin-bottom: 5px !important;
}

.inner_div {
  display: flex;
  ::v-deep {
    .el-input {
      width: 50%;
      display: inline-block;
    }
  }
}
.inner_div2 {
  display: flex;
  ::v-deep {
    .el-input {
      width: 40%;
      display: inline-block;
    }
  }
}
</style>
